package com.example.controller.student;

import com.example.common.Result;
import com.example.entity.DTO.StudentCourseDetailDTO;
import com.example.entity.StudentCourse;
import com.example.service.student.StudentCourseService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentCourseController {
    @Resource
    private StudentCourseService studentCourseService;

    /**
     * 获取全部未选课程详细信息
     */
    @GetMapping("/selectAllCourse")
    public Result selectAllCourse(@RequestParam(defaultValue = "") String courseName,
                                  @RequestParam(defaultValue = "") String teacherName,
                                  @RequestParam(defaultValue = "") Integer studentId) {
        List<StudentCourseDetailDTO> studentCourseDetailDTOS = studentCourseService.selectAllCourse(courseName, teacherName, studentId);
        return Result.success(studentCourseDetailDTOS);
    }

    /**
     * 获取全部已选课程详细信息
     */
    @GetMapping("/selectAllStudentCourse/{studentId}")
    public Result selectAllStudentCourse(@PathVariable Integer studentId) {
        List<StudentCourseDetailDTO> studentCourseDetailDTOS = studentCourseService.selectAllStudentCourse(studentId);
        return Result.success(studentCourseDetailDTOS);
    }

    /**
     * 添加学生选课信息
     */
    @PostMapping("/chooseCourse")
    public Result addStudentCourse(@RequestBody StudentCourse studentCourse) {
        studentCourseService.addStudentCourse(studentCourse);
        return Result.success();
    }

    /**
     * 删除学生选课信息
     */
    @DeleteMapping("/deleteStudentCourse/{id}")
    public Result deleteStudentCourse(@PathVariable Integer id) {
        studentCourseService.deleteStudentCourse(id);
        return Result.success();
    }
}
